home *** CD-ROM | disk | FTP | other *** search
- #include "brlr main window.h"
- #include "brlr load-save.h"
- #include "brlr conversion.h"
- #include "brlr grade 2 meat.h"
- #include "environment.h"
- #include "menus.h"
- #include "main.h"
- #include "util.h"
- #include "text twiddling.h"
- #include "dialogs.h"
- #include "graphics.h"
- #include "window layer.h"
- #include "program globals.h"
-
- static void DealWithKeyPressed(WindowPtr theWindow, unsigned char theChar);
- static void DealWithKeys(void);
-
- enum { key_LeftArrow=0x1c, key_RightArrow, key_UpArrow, key_DownArrow };
- enum { key_PageUp=0x0b, key_PageDown };
- enum { key_Home=0x01 };
- enum { key_End=0x04 };
-
- #define kGrowBoxSize 15
- #define kBrailleFont 10158 /* resource # of braille font */
-
- static short gOldForegroundTime; /* stored foreground wait time */
- static CursHandle gMyIBeamHandle;
- static Boolean gIsActive;
- static Boolean gCharInProgress;
- static unsigned char gTheChar;
-
- static Boolean gSetupDone=FALSE;
-
- void SetupTheMainWindow(WindowPtr theWindow)
- {
- unsigned char *titleStr="\puntitled";
- Point topLeft;
- FSSpec fs;
-
- SetWindowHeight(theWindow, qd.screenBits.bounds.bottom-qd.screenBits.bounds.top-LMGetMBarHeight()-28);
- SetWindowWidth(theWindow, qd.screenBits.bounds.right-qd.screenBits.bounds.left-70);
- SetWindowType(theWindow, zoomDocProc);
- topLeft.v=qd.screenBits.bounds.top+LMGetMBarHeight()+20;
- topLeft.h=qd.screenBits.bounds.left+10;
- SetWindowTopLeft(theWindow, topLeft);
- SetWindowHasCloseBox(theWindow, TRUE);
- SetWindowMaxDepth(theWindow, 1);
- SetWindowDepth(theWindow, 1);
- SetWindowIsFloat(theWindow, FALSE);
- SetWindowTitle(theWindow, titleStr);
- SetWindowAutoCenter(theWindow, FALSE);
- fs.name[0]=0x00;
- fs.vRefNum=0;
- fs.parID=0;
- SetWindowFS(theWindow, fs);
- SetWindowIsModified(theWindow, FALSE);
-
- gTheChar=0x00;
- gCharInProgress=FALSE;
-
- if (gGrade==2)
- OpenTheIndWindow(kFloatingWindow);
-
- if (gSetupDone)
- return;
-
- gMyIBeamHandle=GetCursor(iBeamCursor);
- gSetupDone=TRUE;
- }
-
- void ShutDownTheMainWindow(void)
- {
- ReleaseResource((Handle)gMyIBeamHandle);
- }
-
- void OpenTheMainWindow(WindowPtr theWindow)
- {
- TEHandle hTE;
- FontInfo theFontInfo;
- Rect vScrollBarRect, hScrollBarRect;
- Rect destRect, viewRect;
-
- hTE=GetWindowTE(theWindow);
- if (hTE==0L)
- {
- SetRect(&vScrollBarRect, GetWindowWidth(theWindow)-kGrowBoxSize, -1,
- GetWindowWidth(theWindow)+1, GetWindowHeight(theWindow)+1-kGrowBoxSize);
- SetRect(&hScrollBarRect, -1, GetWindowHeight(theWindow)-kGrowBoxSize,
- GetWindowWidth(theWindow)-kGrowBoxSize+1, GetWindowHeight(theWindow)+1);
- SetWindowVScrollBar(theWindow,
- NewControl(theWindow, &vScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
- SetWindowHScrollBar(theWindow,
- NewControl(theWindow, &hScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
-
- GetTERect(theWindow, &destRect, TRUE);
- viewRect=destRect;
- hTE=TENew(&destRect, &viewRect);
- SetWindowTE(theWindow, hTE);
- TextFont((**hTE).txFont=kBrailleFont);
- TextSize((**hTE).txSize=24);
- TextFace((**hTE).txFace=0);
- GetFontInfo(&theFontInfo);
- (**hTE).fontAscent=theFontInfo.ascent+5;
- (**hTE).lineHeight=theFontInfo.ascent+theFontInfo.descent+theFontInfo.leading+5;
- AdjustViewRect(hTE);
- TEAutoView(TRUE, hTE);
- TESetClickLoop((ProcPtr)MyClikLoop, hTE);
- }
-
- gIsActive=TRUE;
- AdjustVScrollBar(GetWindowVScrollBar(theWindow), hTE);
- AdjustMenus();
- }
-
- void IdleInMainWindow(WindowPtr theWindow, Point mouseLoc)
- {
- KeyMap rawKeys;
- unsigned short theKeys[8];
- TEHandle hTE;
- unsigned char theChar;
-
- if (gInProgress)
- return;
-
- GetKeys(rawKeys);
- Mymemcpy((Ptr)theKeys, (Ptr)rawKeys, sizeof(rawKeys));
- hTE=GetWindowTE(theWindow);
- TEIdle(hTE);
- if ((theKeys[0]) || (theKeys[1]) || (theKeys[2]) || (theKeys[3]&0xfffd) ||
- (theKeys[4]) || (theKeys[5]) || (theKeys[6]) || (theKeys[7]))
- {}
- else if (gCharInProgress)
- {
- theChar=gTheChar+' ';
- gTheChar=0x00;
- gCharInProgress=FALSE;
- DealWithKeyPressed(theWindow, theChar);
- }
-
- if (PtInRect(mouseLoc, &((**hTE).viewRect)))
- {
- if (!gCustomCursor)
- {
- SetCursor(*gMyIBeamHandle);
- gCustomCursor=TRUE;
- }
- }
- else
- {
- gCustomCursor=FALSE;
- }
- }
-
- void KeyPressedInMainWindow(WindowPtr theWindow, unsigned char theChar)
- {
- TEHandle hTE;
- ControlHandle vScrollBar;
-
- if (gInProgress)
- return;
-
- hTE=GetWindowTE(theWindow);
- vScrollBar=GetWindowVScrollBar(theWindow);
-
- if (gPostingEvents)
- {
- DealWithKeyPressed(theWindow, theChar);
- gCharsToPost--;
- if (gCharsToPost==0)
- gPostingEvents=FALSE;
- }
- else
- {
- switch (theChar)
- {
- case key_PageUp:
- ScrollActionProc(vScrollBar, inPageUp);
- break;
- case key_PageDown:
- ScrollActionProc(vScrollBar, inPageDown);
- break;
- case key_Home:
- TEPinScroll(0, TEGetHeight((**hTE).nLines, 1, hTE), hTE);
- break;
- case key_End:
- TEPinScroll(0, -TEGetHeight((**hTE).nLines, 1, hTE), hTE);
- break;
- case ' ':
- case '\r':
- case 0x08:
- case 0x03:
- case key_LeftArrow:
- case key_RightArrow:
- case key_UpArrow:
- case key_DownArrow:
- DealWithKeyPressed(theWindow, theChar);
- break;
- default:
- if (gGrade==1)
- {
- short time, oldTime;
- unsigned char brailleChar;
-
- time=1;
- do
- {
- oldTime=time;
- brailleChar=DealWithLetter(theChar, &time);
- if (brailleChar!=0x00)
- DealWithKeyPressed(theWindow, brailleChar);
- }
- while (oldTime!=time);
- }
- else
- DealWithKeys();
- break;
- }
- }
-
- AdjustVScrollBar(vScrollBar, hTE);
- }
-
- void MouseClickedInMainWindow(WindowPtr theWindow, Point thePoint)
- {
- short partCode;
- ControlHandle theControl;
- short scrollDistance;
- short oldSetting;
- ControlActionUPP scrollActionUPP=NewControlActionProc(ScrollActionProc);
- TEHandle hTE;
-
- if (gInProgress)
- return;
-
- hTE=GetWindowTE(theWindow);
-
- if (PtInRect(thePoint, &((**hTE).viewRect)))
- {
- TEClick(thePoint, (GetTheModifiers()&512) ? TRUE : FALSE, hTE);
- }
- else
- {
- partCode=FindControl(thePoint, theWindow, &theControl);
- if (theControl==GetWindowVScrollBar(theWindow))
- {
- switch (partCode)
- {
- case inThumb:
- oldSetting=GetControlValue(theControl);
- partCode=TrackControl(theControl, thePoint, 0L);
- if (partCode==inThumb)
- {
- scrollDistance=oldSetting-GetControlValue(theControl);
- if (scrollDistance!=0)
- TEPinScroll(0, scrollDistance*(**hTE).lineHeight, hTE);
- }
- break;
- case inUpButton:
- case inDownButton:
- case inPageUp:
- case inPageDown:
- partCode=TrackControl(theControl, thePoint, scrollActionUPP);
- break;
- }
- }
- }
- }
-
- Boolean CloseTheMainWindow(WindowPtr theWindow)
- {
- WindowPtr floatingWindow;
- ModalFilterUPP procFilter = NewModalFilterProc(ThreeButtonFilter);
- short result;
-
- if (WindowIsModifiedQQ(theWindow))
- {
- SetCursor(&qd.arrow);
- PositionDialog('ALRT', saveAlert);
- ParamText(GetWindowTitle(theWindow), "\p", "\p", "\p");
- result=Alert(saveAlert, procFilter);
- DisposeRoutineDescriptor(procFilter);
- switch (result)
- {
- case 1: /* save */
- LoadSaveDispatch(FALSE, TRUE);
- if (WindowIsModifiedQQ(theWindow)) /* save didn't work for some reason */
- return FALSE;
- break;
- case 2: /* cancel */
- return FALSE;
- break;
- case 3: /* don't save */
- break;
- }
- }
-
- floatingWindow=GetIndWindowPtr(kFloatingWindow);
- if (floatingWindow!=0L)
- CloseTheWindow(floatingWindow);
-
- gCustomCursor=FALSE;
-
- return TRUE;
- }
-
- void DisposeTheMainWindow(WindowPtr theWindow)
- {
- TEHandle hTE;
-
- hTE=GetWindowTE(theWindow);
- if (hTE!=0L)
- {
- TEDispose(hTE);
- SetWindowTE(theWindow, 0L);
- }
- }
-
- void ActivateTheMainWindow(WindowPtr theWindow)
- {
- gOldForegroundTime=gForegroundWaitTime;
- gForegroundWaitTime=0;
- TEActivate(GetWindowTE(theWindow));
- gIsActive=TRUE;
- HiliteControl(GetWindowVScrollBar(theWindow), 0);
- HiliteControl(GetWindowHScrollBar(theWindow), 0);
- DrawGrowIcon(theWindow);
- }
-
- void DeactivateTheMainWindow(WindowPtr theWindow)
- {
- Rect tempRect;
-
- gForegroundWaitTime=gOldForegroundTime;
- TEDeactivate(GetWindowTE(theWindow));
- gIsActive=FALSE;
- gCustomCursor=FALSE;
- HiliteControl(GetWindowVScrollBar(theWindow), 255);
- HiliteControl(GetWindowHScrollBar(theWindow), 255);
- tempRect.bottom=theWindow->portRect.bottom;
- tempRect.right=theWindow->portRect.right;
- tempRect.left=tempRect.right-kGrowBoxSize+1;
- tempRect.top=tempRect.bottom-kGrowBoxSize+1;
- EraseRect(&tempRect);
- }
-
- void CopybitsTheMainWindow(WindowPtr theWindow, WindowPtr offscreenWindowPtr)
- {
- Rect tempRect;
-
- if (gIsActive)
- {
- DrawGrowIcon(theWindow);
- }
- else
- {
- tempRect.bottom=theWindow->portRect.bottom;
- tempRect.right=theWindow->portRect.right;
- tempRect.left=tempRect.right-kGrowBoxSize+1;
- tempRect.top=tempRect.bottom-kGrowBoxSize+1;
- EraseRect(&tempRect);
- }
-
- UpdateControls(theWindow, theWindow->visRgn);
-
- tempRect=theWindow->portRect;
- tempRect.bottom-=kGrowBoxSize;
- tempRect.right-=kGrowBoxSize;
- CopyBits( &(offscreenWindowPtr->portBits),
- &(theWindow->portBits),
- &tempRect, &tempRect, 0, 0L);
- }
-
- void ResizeControlsInMainWindow(WindowPtr theWindow)
- {
- TEHandle hTE;
- ControlHandle vScrollBar, hScrollBar;
-
- hTE=GetWindowTE(theWindow);
- vScrollBar=GetWindowVScrollBar(theWindow);
- hScrollBar=GetWindowHScrollBar(theWindow);
- AdjustScrollSizes(theWindow, hTE, vScrollBar, hScrollBar);
- AdjustViewRect(hTE);
- TECalText(hTE);
- AdjustForEndScroll(vScrollBar, hTE);
- AdjustVScrollBar(vScrollBar, hTE);
- }
-
- void GetGrowSizeMainWindow(WindowPtr theWindow, Rect *sizeRect)
- {
- SetRect(sizeRect, 200, 48+kGrowBoxSize+1, 32766, 32767);
- }
-
- /* ---------------------------------------------------- */
- /* the rest of these are internal to brlr main window.c */
-
- static void DealWithKeyPressed(WindowPtr theWindow, unsigned char theChar)
- {
- TEHandle hTE;
-
- hTE=GetWindowTE(theWindow);
- TEKey(theChar, hTE);
- TESelView(hTE);
- AdjustForEndScroll(GetWindowVScrollBar(theWindow), hTE);
- SetWindowIsModified(theWindow, TRUE);
- }
-
- static void DealWithKeys(void)
- {
- KeyMap rawKeys;
- unsigned short theKeys[8];
-
- GetKeys(rawKeys);
- Mymemcpy((Ptr)theKeys, (Ptr)rawKeys, sizeof(rawKeys));
- if (theKeys[0]&16384) { gTheChar|=0x04; gCharInProgress=TRUE; }
- if (theKeys[0]&32768) { gTheChar|=0x02; gCharInProgress=TRUE; }
- if (theKeys[0]&1) { gTheChar|=0x01; gCharInProgress=TRUE; }
- if (theKeys[2]&8) { gTheChar|=0x08; gCharInProgress=TRUE; }
- if (theKeys[2]&128) { gTheChar|=0x10; gCharInProgress=TRUE; }
- if (theKeys[2]&16) { gTheChar|=0x20; gCharInProgress=TRUE; }
- }
-